package com.itheima;

import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;

public class 函数式接口 {
    public static void main(String[] args) {
        /*Object o = fun1(new Supplier() {
            @Override
            public Object get() {
                return "hello";
            }
        });
        System.out.println(o);*/
       // System.out.println(fun1(()->"hello"));
      //  fun2(s-> System.out.println(s),"hello");
       // System.out.println(fun3((s)->s.startsWith("张"), "张三"));
        System.out.println(fun4((s)->Integer.parseInt(s), "123"));
    }

    /**
     * 生产性接口
     * 无参有返回值.
     *  T get();
     * @param sp
     */
    public static  Object fun1(Supplier sp){
        return sp.get();
    }

    /**
     * 消费型接口
     * 有参数,无返回值
     *  void accept(T t);
     * @param c
     * @return
     */
    public static  void fun2(Consumer c,String s){
         c.accept(s);
    }

    /**
     * 判断型接口
     *   有参数返回boolean值
     *  boolean test(T t);
     * @param p
     * @param s
     */
    public static  boolean fun3( Predicate<String> p,String s){
        return  p.test(s);
    }

    /**
     * 转换型接口:
     *   有参,有返回值.
     *     R apply(T t);
     * @param function
     * @param s
     * @return
     */
    public static  Integer fun4(Function<String,Integer> function,String s){
        return function.apply(s);
    }
}
